<?php include _include(APP_PATH.'view/htm/header.inc.htm');?>

<div class="row">
	<div class="col-lg-6 offset-lg-3">
		<div class="card card-block m-t-1">
			<h4 class="card-title"><?php echo lang('modify_password');?></h4>
			<form action="<?php echo url('my-password');?>" method="post" id="form">
				<p class="input-group">
					<span class="input-group-addon"><i class="icon icon-lock"></i></span>
					<input type="password" class="form-control" placeholder="<?php echo lang('password_old');?>" name="password_old" id="password_old">
				</p>
				<p class="input-group">
					<span class="input-group-addon"><i class="icon icon-lock"></i></span>
					<input type="password" class="form-control" placeholder="<?php echo lang('password_new');?>" name="password_new" id="password_new">
				</p>
				<p class="input-group">
					<span class="input-group-addon"><i class="icon icon-lock"></i></span>
					<input type="password" class="form-control" placeholder="<?php echo lang('password_new_repeat');?>" name="password_new_repeat" id="password_new_repeat">
				</p>
				<p>
					<button type="submit" class="btn btn-primary btn-block" id="submit" data-loading-text="<?php echo lang('submiting');?>..."><?php echo lang('update_password');?></button>
					<a role="button" class="btn btn-secondary center-block m-t-1" href="<?php echo url('my');?>"> <?php echo lang('back');?> </a>
				</p>
			</form>
		</div>
	</div>
</div>

<?php include _include(APP_PATH.'view/htm/footer.inc.htm');?>
<script src="<?php echo $conf['view_url'];?>js/md5.js"></script>

<script>

var jform = $('#form');
var jsubmit = $('#submit');
jform.on('submit', function() {
	jform.reset();
	jsubmit.button('loading');
	var postdata = jform.serializeObject();
	postdata.password_old = $.md5(postdata.password_old);
	postdata.password_new = $.md5(postdata.password_new);
	postdata.password_new_repeat = $.md5(postdata.password_new_repeat);
	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			$.alert(message);
			jsubmit.button(message).delay(3000).button('reset');
		} else if(code < 0) {
			$.alert(message);
			jsubmit.button('reset');
		} else {
			jform.find('[name="'+code+'"]').alert(message).focus();
			jsubmit.button('reset');
		}
	});
	return false;
});
</script>